﻿
using System;
using System.Collections.Specialized;
using System.Globalization;

namespace LiveMail
{
    /// <summary>
    /// imap mail. fail for fxcop while naming as imap
    /// </summary>
    public class InteractiveMail : TestMailBase
    {
        /// <summary>
        /// ctor method.
        /// </summary>
        public InteractiveMail(string host, int port, bool useSsl)
            : base(host, port, useSsl)
        {
        }

        /// <summary>
        /// user login.
        /// </summary>
        public override void AuthenticateUser(string user, string pass)
        {
            SendCommand(string.Format(CultureInfo.InvariantCulture, "$ LOGIN {0} {1}", new object[] { user, pass }));
        }

        /// <summary>
        /// get total mail count.
        /// </summary>
        public override int ReadMailCount()
        {
            SendCommand("$ SELECT INBOX");
            return TestMailBase.ParseMailCountText(base.SendCommand("$ STATUS INBOX (messages)"));
        }

        /// <summary>
        /// get mail header content by header text.
        /// </summary>
        /// <param name="id">mail id.</param>
        public override NameValueCollection GetMail(int id)
        {
            return InternalGetMail(string.Format(CultureInfo.InvariantCulture, "$ FETCH {0} (body[header.fields (from to subject)])", id));
        }
    }
}
